import { message } from "antd";
import { dayPoint, weekPoint } from "./constants";
import { getCronSplitValue } from "./help";

export const validateCronStringValue = (cronValue: string) => {
  const cronSplitValue = getCronSplitValue(cronValue || "");
  const weekValue = cronSplitValue[weekPoint];
  const isWeekMode = weekValue != "?" && weekValue != "*";
  if (isWeekMode) {
    const weekValidate =
      weekValue.split(",").filter((w) => w && w != "0").length > 0;
    if (!weekValidate) {
      message.warning("请指定每周执行次数");
      return false;
    }
  }
  const dayValue = cronSplitValue[dayPoint];
  const isDayMode = dayValue != "?" && dayValue != "*";
  if (isDayMode) {
    const dayValidate =
      dayValue.split(",").filter((w) => w && w != "0").length > 0;
    if (!dayValidate) {
      message.warning("请指定每月执行次数");
      return false;
    }
  }
  return true;
};
